#pragma once
#include "stdafx.h"

#include "MessageListPane.h"
#include "FolderTreeCtrl.h"
#include "Resource.h"
#include "WindowsGui.h"
#include "NavigationBar.h"

using namespace System;

BOOL CNavigationBar::AllowShowOnPaneMenu() const 
{ 
	return TRUE; 
}
void CNavigationBar::GetPaneName(CString& strName) const 
{ 
	BOOL bNameValid = strName.LoadString(IDS_OUTLOOKBAR); 
	ASSERT(bNameValid); 
}

int CNavigationBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMFCOutlookBar::OnCreate(lpCreateStruct) == -1)
		return -1;

	CMFCOutlookBarTabCtrl* pOutlookBar = (CMFCOutlookBarTabCtrl*)(this->GetUnderlyingWindow());

	if (pOutlookBar == NULL)
	{
		ASSERT(FALSE);
		return FALSE;
	}

	BOOL bNameValid;
	CString strTemp, strTemp2;
	CRect rectDummy(0, 0, 0, 0);
	static UINT uiPageID = 1;

	const DWORD dwPaneStyle = AFX_DEFAULT_TOOLBAR_STYLE | CBRS_FLOAT_MULTI;

	// can float, can auto hide, can resize, CAN NOT CLOSE
	const DWORD dwStyle = AFX_CBRS_FLOAT | AFX_CBRS_AUTOHIDE | AFX_CBRS_RESIZE | AFX_CBRS_AUTO_ROLLUP;

	const DWORD dwTreeStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_FULLROWSELECT | TVS_EDITLABELS;

	m_wndFolderTree.Create(dwTreeStyle, rectDummy, this, 1200);

	bNameValid = strTemp.LoadString(IDS_FOLDERS);
	ASSERT(bNameValid);
	pOutlookBar->AddControl(&m_wndFolderTree, strTemp, 2, TRUE, dwStyle);



	this->SetPaneStyle(this->GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

	pOutlookBar->SetImageList(IDB_NAV_PANES_L, 24);
	pOutlookBar->SetToolbarImageList(IDB_NAV_PANES_S, 16);
	pOutlookBar->RecalcLayout();

	CMFCOutlookBarTabCtrl::EnableAnimation(TRUE);

	this->SetButtonsFont(&afxGlobalData.fontBold);

	return 0;
}
BEGIN_MESSAGE_MAP(CNavigationBar, CMFCOutlookBar)
	ON_WM_CONTEXTMENU()
	ON_WM_CREATE()
END_MESSAGE_MAP()

void CNavigationBar::OnContextMenu(CWnd* pWnd, CPoint point)
{
	if (pWnd->GetSafeHwnd() != m_wndFolderTree.GetSafeHwnd())
	{
		CDockablePane::OnContextMenu(pWnd, point);
	}
	else
	{
		// Select clicked item:
		CPoint ptTree = point;
		m_wndFolderTree.ScreenToClient(&ptTree);

		UINT flags = 0;
		HTREEITEM hItem = m_wndFolderTree.HitTest(ptTree, &flags);
		if (hItem != NULL)
		{
			m_wndFolderTree.SelectItem(hItem);
		}
		m_wndFolderTree.SetFocus();
		VERIFY(theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_FOLDERS,point.x,point.y,this));
	}

}


